<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <style type="text/css">
        *{
            margin: 0px;
            padding: 0px;
        }
        body{
            width: 100%;
            height: 100%;
            background-color: #ebf6ff;
            background-image: url("img/background.jpg");
        }
        #main{
            width: 300px;
            height: 200px;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-left: -150px;
            margin-top: -200px;
        }
        #main input{
            width: 280px;
            height: 40px;
            border: 1px solid black;
            border-radius: 5px;
            margin: 10px;
            box-sizing: border-box;
            background:transparent;
            outline: none;
        }
        #main .user{
            background-image: url("img/ren.png");
            background-repeat: no-repeat;
            background-position-y: center;
            padding-left: 30px;
            background-position-x:5px ;
        }
        #main .pwd{
            background-image: url("img/suo.png");
            background-repeat: no-repeat;
            padding-left: 30px;
            background-position-x:5px ;
            background-position-y: center;
        }
        #main button{
            width: 120px;
            height: 30px;
            font-size: 16px;
            cursor: pointer;
            border-radius: 5px;
            border: 1px solid gray;
            margin: 10px;
            background: transparent;
            outline: none;
        }
        #main button:hover{
            color: white;
            background-color: gainsboro;
        }
        #main div{
            text-align: center;
            font-size: 12px;
        }
        #main #contant{
            width: 200px;
            height: 80px;
            background-image: url("img/app.png");
            background-position-y: center;
            background-repeat: no-repeat;
            background-size: 48px;
            line-height: 70px;
            margin-left: 50px;
            font-size: 30px;
        }
        #main a:hover{
            color: red;
        }
    </style>
</head>
<body>
    <div id="main">
        <div id="contant">记账本</div>
        <form action="#" method="post" autocomplete="off">
            <div>
                <input type="text" name="user" id="user"
                       placeholder="用户名/手机号/邮箱" class="user">
                <span id="userTip"> </span>
            </div>
            <div>
                <input type="text" name="pwd" id="pwd" placeholder="密码" class="pwd">
                <span id="pwdTip"> </span>
            </div>
            <div>
                <button type="submit">登录</button>
            </div>
            <div style="text-align: right;">
                <a href="">密码找回</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="">快速注册</a>
            </div>
        </form>
    </div>
</body>
<script>
    var user = document.getElementById("user");
    var userTip = document.getElementById("userTip");
    user.onblur = function loginUser() {
        let userName = user.value;
        let name = /^[a-zA-z]{1}[a-zA-z0-9]{5,15}$/;
        if(!name.test(userName)){
            user.innerText = null;
            userTip.innerHTML = "用户名为字母开头，由6到16位字母数字组成";
        }else{
            userTip.innerHTML = " ";
        }
    }
    var pwd = document.getElementById("pwd");
    var pwdTip = document.getElementById("pwdTip");
    pwd.onblur = function loginPwd() {
        let pwdName = pwd.value;
        let pname = /^[a-zA-z0-9]{6,16}$/;
        if(!pname.test(pwdName)){
            pwd.innerText = null;
            pwdTip.innerHTML = "密码由6到16位字母数字组成";
        }else{
            pwdTip.innerHTML = " ";
        }
    }
</script>
</html>